package gossip.v2;

import gossip.v2.protocol.GossipProtocol;
import gossip.v2.protocol.GossipMessageProcessor;
import org.ricks.net.extension.plugins.IdleStatePlugin;
import org.ricks.net.transport.AioQuickServer;
import java.io.IOException;

public class GossipServer {
    private final AioQuickServer server;

    public GossipServer(int port, GossipCore core) {
        GossipMessageProcessor processor = new GossipMessageProcessor(core);
        this.server = new AioQuickServer(port, new GossipProtocol(core), processor);
        // 添加空闲检测
        processor.addPlugin(new IdleStatePlugin<>(10000));
    }

    public void start() {
        try {
            server.start();
        } catch (IOException e) {
            throw new RuntimeException("Server start failed", e);
        }
    }

    public void shutdown() {
        server.shutdown();
    }
}
